package com.dz.risk.service.impl;

import com.dz.risk.constant.IndexConstant;
import com.dz.risk.pojo.domain.ReportFormsDataValueEntity;
import com.dz.risk.service.IndexDealWith;
import com.dz.risk.service.SqlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;

/**
 * @author Doke
 * @date 2021/9/7 13:21
 */
@Service("IndexDealWith_" + IndexConstant.SQL_COMPUTING)
public class IndexDealWithThreeImpl implements IndexDealWith {

    private final SqlService sqlService;

    @Autowired
    public IndexDealWithThreeImpl(SqlService sqlService) {
        this.sqlService = sqlService;
    }

    /**
     * 根据报表单元格信息和计算时间获取指标数据
     *
     * @param reportFormsDataValueEntity 报表单元格信息
     * @param calculatingTime            计算版本
     * @param beginDate                  报表开始时间
     * @param endDate                    报表结束时间
     * @return 数据值
     */
    @Override
    public Double getDataByReportFormsDataValueAndCalculatingTime(ReportFormsDataValueEntity reportFormsDataValueEntity, Date calculatingTime, Date beginDate, Date endDate) {
        Double value = null;
        if (Objects.nonNull(reportFormsDataValueEntity.getFormula())) {
            BigDecimal numeration = sqlService.numberation(reportFormsDataValueEntity.getFormula().getFormulaDetails(), calculatingTime);
            value = Objects.isNull(numeration) ? null : numeration.doubleValue();
        }

        return value;
    }
}
